package com.cskaoyan.order.biz.handler;

import com.cskaoyan.mall.dto.ClearCartItemRequest;
import com.cskaoyan.mall.dto.ClearCartItemServiceResponse;
import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.remote.ProductApiClient;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Slf4j
@Component
public class ClearCartItemHandler extends AbstractTransHandler {

    @Autowired
    RedissonClient redissonClient;
    @Autowired
    ProductApiClient productApiClient;

    //是否采用异步方式执行
    @Override
    public boolean isAsync() {
        return false;
    }

    @Override
    public boolean handle(TransHandlerContext context) {
        //TODO 下单的同时删除购物车中的商品
        CreateOrderContext createOrderContext = (CreateOrderContext) context;
        //TODO 1 拿到用户的id删除购物车中的商品
        //TODO 调用shoping层的feignclient
        ClearCartItemRequest clearCartItemRequest = new ClearCartItemRequest();
        clearCartItemRequest.setProductIds(createOrderContext.getBuyProductIds());
        clearCartItemRequest.setUserId(createOrderContext.getUserId());
        productApiClient.clearCartItemByUserID(clearCartItemRequest);
        return true;
    }
}
